# =============================================================================
# Aumni AMS — public web root
#
# On cPanel the contents of this directory are what live in public_html. The
# application itself sits outside the web root, so nothing below can expose
# source, .env or logs even if a rule here is wrong.
# =============================================================================

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Handle X-XSRF-Token Header
    RewriteCond %{HTTP:x-xsrf-token} .
    RewriteRule .* - [E=HTTP_X_XSRF_TOKEN:%{HTTP:X-XSRF-Token}]

    # ---------------------------------------------------------------------
    # Force HTTPS.
    #
    # Enabled in Phase 13, once AutoSSL has issued a certificate for the
    # production hostname. Turning it on before that locks everyone out.
    # ---------------------------------------------------------------------
    # RewriteCond %{HTTPS} !=on
    # RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

# -----------------------------------------------------------------------------
# Never serve dotfiles (.env, .git, .htaccess itself).
# -----------------------------------------------------------------------------
<FilesMatch "^\.">
    Require all denied
</FilesMatch>

# -----------------------------------------------------------------------------
# Compiled assets carry a content hash in their filename, so they can be cached
# indefinitely: a change produces a new filename, never a stale file.
# -----------------------------------------------------------------------------
<IfModule mod_headers.c>
    <FilesMatch "\.(css|js|woff2?|svg|png|jpe?g|ico)$">
        Header set Cache-Control "public, max-age=31536000, immutable"
    </FilesMatch>
</IfModule>

<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml
    AddOutputFilterByType DEFLATE application/javascript application/json
    AddOutputFilterByType DEFLATE image/svg+xml
</IfModule>

# -----------------------------------------------------------------------------
# This is an internal system. It must never appear in a search index.
# -----------------------------------------------------------------------------
<IfModule mod_headers.c>
    Header set X-Robots-Tag "noindex, nofollow"
</IfModule>
